<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/default/easyui.css"/>">
<link rel="stylesheet" type="text/css" href="<c:url value="/css/themes/icon.css"/>">

<script type="text/javascript" src="<c:url value="/js/jquery.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/jquery.easyui.min.js"/>"></script>
<script type="text/javascript" src="<c:url value="/js/easyui-lang-zh_CN.js"/>"></script>
<title>供应商管理</title>
</head>
<body>

<style>
	* {
		font-size: 12px;
	}
	
	.yzr-supp-item{
		margin-top: 5px;
	}
</style>
<script type="text/javascript">
$(function(){
	
		 $.extend($.fn.validatebox.defaults.rules,{ 
	         phone:{ 
	             validator: function (value) {   
	                    return /^((\d2,3)|(\d{3}\-))?(0\d2,3|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);   
	                },   
	                message: '电话号码格式不正确'  
	         },
	         fax:{ 
	             validator: function (value) {   
	                    return /^((\d2,3)|(\d{3}\-))?(0\d2,3|0\d{2,3}-)?[1-9]\d{6,7}(\-\d{1,4})?$/i.test(value);   
	                },   
	                message: '传真格式不正确'  
	         },
	          
	     }); 		
		//打开添加供应商的窗口
		$("#yzr-supp-add").linkbutton({onClick: function(){
			$('#yzr-supp-window').window({'title': "录入供应商"});
			$('#yzr-supp-form').form("clear");
			$("#yzr-supp-window").window("open");
		}});
		
		//提交添加/编辑供应商的请求
		$("#yzr-supp-btnok").linkbutton({onClick: function(){
			var title = $('#yzr-supp-window').window("options").title;
			var url = (title == '录入供应商' ? 'addSupplier' : 'editSupplier');
			$('#yzr-supp-form').form('submit', {
				url: url,
			    onSubmit: function(){
			    	return $(this).form("validate");
			    },
			    success:function(data){
			    	var json = eval("(" + data + ")");
					$.messager.alert("提示", json.reason);
					$('#yzr-supp-window').window('close');
					$("#tb-supplier").datagrid("reload");
					$(this).form("clear");
			    }
			});
		}});
		
		//打开编辑供应商的窗口
		$("#yzr-supp-edit").linkbutton({onClick: function(){
			var rows = $("#tb-supplier").datagrid("getSelections");
			if(rows.length == 1){
				$('#yzr-supp-window').window({'title': "编辑供应商"});
				$('#yzr-supp-window').window("open");
				var sId = rows[0].supId;
				$.getJSON("querySupplierById", {"supId": sId}, function(data){
					$("#yzr-supp-form").form("load", data);
				});
				
			}else{
				$.messager.alert("提示", "只能选择一条记录，您目前选择了" + rows.length + "条!");
			}
			
		}});
		
		//批量删除
		/* $("#yzr-supp-delete").linkbutton({onClick: function(){
			var rows = $("#tb-supplier").datagrid("getSelections");
			if(rows.length >= 1){
				$.messager.confirm("提示", "确定要删除吗？", function(v){
					if(v){
						var rows = $("#tb-supplier").datagrid("getSelections");
						var arr = [];
						for(var i = 0; i < rows.length; i ++){
							arr.push(rows[i].supId);
						}
						$('<form>').form('submit', {
						    url:'delSupplier',
						    onSubmit: function(param){
						    	param.list = arr;
						    },
						    success:function(data){
						    	var json = eval("(" + data + ")");
								$.messager.alert("提示", json.reason);
								$("#tb-supplier").datagrid("reload");
						    }
						});
					}
				});
			}else{
				$.messager.alert("提示", "至少选择一条记录，您目前选择了" + rows.length + "条!");
			}
		}}); */
		
		//显示全部
		$("#yzr-supp-reload").linkbutton({onClick:function(){
			$("#tb-supplier").datagrid({
	    		url: 'queryAllSupplier', 
	    		method: 'get'
	    	});
		}});
		
		//根据供应商名称模糊查询供应商 
		$('#yzr-supp-search').searchbox({
		    searcher:function(value,name){
		    	if(value == ''){
		    		$.messager.alert("提示", "请输入查询条件！");
		    	}else{
		    		$("#tb-supplier").datagrid({	    			    		
			    		url: name == 'name' ? 'querySupplierByName' : 'querySupplierByKind',
			    		method: 'post', 
			    		queryParams: {
			    			pharmacyName: value
			    	}});
			    	$('#yzr-supp-search').searchbox('setValue', '');
		    	}		    	
		    }		    
		}); 
		
	});
</script>

	<table id="tb-supplier" class="easyui-datagrid" 
		data-options="url:'queryAllSupplier',
			fitColumns:true,
			fit:true,
			striped:true,
			pagination: true,
			pageSize: 16,
			pageList: [16, 32, 48, 54],
			rownumbers: true,
			toolbar: '#yzr-supp-tb',
			border:false
			">
		<thead>
			<tr>		
				<th data-options="field:'supId',width:'4%',checkbox:true">供应商编号</th>				
				<th data-options="field:'supName',width:'20%',align:'center'">供应商名称</th>
				<th data-options="field:'supKind',width:'14%',align:'center'">类型</th>
				<th data-options="field:'supPhone',width:'13%',align:'center'">电话</th>
				<!-- <th data-options="field:'supFax',width:'8%'">传真</th> -->
				<th data-options="field:'supContext',width:'10%',align:'center'">联系人</th>
				<!-- <th data-options="field:'supDeliveryMode',width:'10%'">送货方式</th> -->
				<!-- <th data-options="field:'supCredit',width:'10%'">信誉评定</th> -->
				<th data-options="field:'supPayment',width:'10%',align:'center'">付款方式</th>
				<th data-options="field:'supAddress',width:'20%',align:'center'">地址</th>
				<th data-options="field:'supExplain',width:'12%',align:'center'">备注</th>
				
			</tr>
		</thead>
	</table>
	
	<div id="yzr-supp-tb">
		<a id="yzr-supp-add" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true">添加供应商</a>
		<a id="yzr-supp-edit" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">修改供应商</a>
		<!-- <a id="yzr-supp-delete" class="easyui-linkbutton" data-options="iconCls:'icon-cancel',plain:true">删除供应商</a> -->
		<a id="yzr-supp-reload" class="easyui-linkbutton" data-options="iconCls:'icon-reload',plain:true">刷新</a>
		<input id="yzr-supp-search" class="easyui-searchbox" data-options="menu: '#yzr-supp-pName', width: 250, prompt: '请输入关键字'"/>
	</div> 
	
	<div id="yzr-supp-pName" style="width:140px">
	    <div data-options="name:'name'">供应商名称</div>
	    <div data-options="name:'kind'">供应商类型</div>
	</div>
	
	<!-- 添加/修改药房窗口 -->
	<div id="yzr-supp-window" class="easyui-window" title="录入供应商" data-options="collapsible:false,minimizable:false,maximizable:false,modal:true,iconCls:'icon-save',closed: true" style="width:400px;height:420px;padding:5px;">
		<div class="easyui-layout" data-options="fit:true">
			<div data-options="region:'center'" style="padding:10px;">
				<form id="yzr-supp-form" method="post">
					<div class="yzr-supp-item" style="display:none;"><input name="supId" class="easyui-textbox"  data-options="label: '供应商编号', width: 280,readonly:true"></div>
					<div class="yzr-supp-item"><input name="supName" class="easyui-textbox" data-options="label: '供应商名称', width: 250, required:true, missingMessage: '账户不能为空', invalidMessage: '账户的长度必须在3-20间', validType: { length:[3,50] }"></div>
					<div class="yzr-supp-item">
						<select class="easyui-combobox" name="supKind" data-options="label: '供应商类型', width: 200, required:true,panelHeight:65">
						    <option value="药品供应">药品供应</option>
						    <option value="器械供应">器械供应</option>
						    <option value="耗材供应">耗材供应</option>
						</select>
					</div>
					<div class="yzr-supp-item"><input name="supPhone" class="easyui-textbox" data-options="label: '电话', width: 250, required:true,validType: ['phone']"></div>
					<div class="yzr-supp-item"><input name="supFax" class="easyui-textbox" data-options="label: '传真', width: 250,validType: ['fax']"></div>
					<div class="yzr-supp-item"><input name="supContext" class="easyui-textbox" data-options="label: '联系人', width: 200, required:true"></div>
					
					<div class="yzr-supp-item">
						<select class="easyui-combobox" name="supDeliveryMode" data-options="label: '送货方式', width: 200, panelHeight:85">
						    <option value="快递">快递</option>
						    <option value="货运">货运</option>
						    <option value="送货上门">送货上门</option>
						    <option value="自取">自取</option>
						</select>
					</div>
					
					<div class="yzr-supp-item">
						<select class="easyui-combobox" name="supCredit" data-options="label: '信誉评定', width: 200, required:true,panelHeight:85">
						    <option value="非常好">非常好</option>
						    <option value="良好">良好</option>
						    <option value="一般">一般</option>
						    <option value="差">差</option>
						</select>
					</div>
					
					<div class="yzr-supp-item">
						<select class="easyui-combobox" name="supPayment" data-options="label: '付款方式', width: 200, required:true,panelHeight:105">
						    <option value="现金">现金</option>
						    <option value="转账">转账</option>
						    <option value="支票">支票</option>
						    <option value="刷卡">刷卡</option>
						    <option value="其他">其他</option>
						</select>
					</div>
					
					<div class="yzr-supp-item"><input name="supAddress" class="easyui-textbox" data-options="label: '地址', width: 300, required:true"></div>
					<div class="yzr-supp-item"><input name="supExplain" class="easyui-textbox" data-options="label: '备注', width: 300"></div>
				</form>
			</div>
			<div data-options="region:'south',border:false" style="text-align:right;padding:5px 0 0;">
				<a id="yzr-supp-btnok" class="easyui-linkbutton" data-options="iconCls:'icon-ok', plain:true" >确定</a>
				<a class="easyui-linkbutton" data-options="iconCls:'icon-cancel', plain:true" href="javascript:$('#yzr-supp-window').window('close');" onclick="">取消</a>
			</div>
		</div>
	</div>
</body>
</html>